The earthquake data is from USGS.gov. Variables in the dataset and their meanings:
p1 <- temp %>%
mutate(date = lubridate::floor_date(timestamp, 'weeks'),
is_day = if_else(is_day, '日间', '夜间')) %>%
count(date, is_day) %>%
ggplot(aes(date, n)) +
geom_line(aes(color = is_day)) +
geom_smooth(aes(color = is_day), se = FALSE) +
scale_color_manual(values = c('日间' = '#ffb84d', '夜间' = '#3a6589')) +
labs(x = NULL, y = 'count weekly', title = 'earthquake count on if happened at night',
color = NULL,
subtitle = 'mag level >= 2.5\nruns test p value: 0.7009211',
caption = 'dataSource: USGS.gov') +
theme_minimal() +
theme(legend.position = 'bottom')
p2 <- temp %>%
filter(mag >= 4.5) %>%
mutate(date = lubridate::floor_date(timestamp, 'weeks'),
is_day = if_else(is_day, '日间', '夜间')) %>%
count(date, is_day) %>%
ggplot(aes(date, n)) +
geom_line(aes(color = is_day)) +
geom_smooth(aes(color = is_day), se = FALSE) +
scale_color_manual(values = c('日间' = '#ffb84d', '夜间' = '#3a6589')) +
labs(x = NULL, y = 'count weekly', title = 'earthquake count on if happened at night',
color = NULL,
subtitle = 'mag level >= 4.5\nruns test p value: 0.6062803',
caption = 'dataSource: USGS.gov') +
theme_minimal() +
theme(legend.position = 'bottom')
cowplot::plot_grid(p1, p2)runs_test <- function(x) {
R <- length(rle(x)$length) # observed runs
n_1 <- length(x[x == 0])
n_2 <- length(x[x == 1])
R_ <- (2 * n_1 * n_2) / (n_1 + n_2) + 1 # expected runs
s_R <- (2 * n_1 * n_2 * (2 * n_1 * n_2 - n_1 - n_2)) / ( (n_1 + n_2)^2 * (n_1 + n_2 - 1) )
Z <- (R - R_) / s_R # test statitics
# H0: the sequence was produced in a random manner
# Ha: the sequence was not produced in a random manner
p.value <- 2 * pnorm(-abs(Z))
p.value
}A work by ashther